const program = require('commander')
const path = require('path')

const actionMap = {
  create: {
    description: 'create project',
    alias: 'c',
    example: ['zero create <project-name>']
  },
  config: {
    description: 'config info',
    alias: 'conf',
    example: [
      'zero config get <key>',
      'zero config set <key> <value>'
    ]
  },
  '*': {
    description: 'command not found'
  }
}

Object.keys(actionMap).forEach((action) => {
  program
    .command(action)
    .alias(actionMap[action].alias)
    .description(actionMap[action].description)
    .action(() => {
      if(action === '*') {
        console.log(actionMap[action].description)
      }else {
        require(path.resolve(__dirname, action))(...process.argv.slice(3))
      }
    })
})

program
  .version(require('./../package.json').version)

program.on('--help', () => {
  console.log('Examples')
  Object.keys(actionMap).forEach((action) => {
    actionMap[action].example.forEach((example) => {
      console.log(`  ${example}`)
    })
  })
})

program.parse(process.argv)
